package PlotPourri;

import java.util.ArrayList;
import java.util.List;

public class Star {

    public enum Type {

        BLHer, WVir;
    }

    public enum PulsationMode {

        FO, FU, FA, BR;
    }
    private PulsationMode cl = PulsationMode.values()[0];
    private Type type = Type.values()[0];
    private double period;
    private int name;
    private List<Band> Bands;

    public Star(BandName[] values, int name) {
        this.name = name;
        Bands = new ArrayList<Band>();
        for (BandName bandName : values) Bands.add(new Band(bandName));
    }
    
    public Star(BandName band, int name) {
        this.name = name;
        Bands = new ArrayList<Band>();
        Bands.add(new Band(band));
    }

    public double[] AkBk(int order, BandName band, double threshold) {
        // fix me!
        return getBand(band).get(0).getAkBk(order, threshold);
    }

    public double Ao(int order, BandName band) {
        // fix me!
        return getBand(band).get(0).getAo(order);
    }

    public double R21(int order, BandName band) {
        // fix me!
        List<Double> A = getBand(band).get(0).getA(getBand(band).get(0).getCoefficients(order));
        return (A.get(0) != 0) ? A.get(1) / A.get(0) : 0;
    }

    public double Phi21(int order, BandName band) {
        // fix me!
        List<Double> Phi = getBand(band).get(0).getPhi(getBand(band).get(0).getCoefficients(order));
        double value = Phi.get(1) - 2 * Phi.get(0);
        while (value < 0) value += 2 * Math.PI;
        return value;
    }

    public double AmpV(int order) {
        // fix me!
        double[][] V = getBand(BandName.V).get(0).getData(order, 100);
        double maximum = Double.NEGATIVE_INFINITY;
        double minimum = Double.POSITIVE_INFINITY;
        for (int i = 0; i < V.length; i++) {
            if (V[i][1] > maximum) maximum = V[i][1];
            if (V[i][1] < minimum) minimum = V[i][1];
        }
        return maximum - minimum;
    }

    public double VIMax(int order) {
        // fix me!
        double[][] V = getBand(BandName.V).get(0).getData(order, 100);
        double maximum = Double.POSITIVE_INFINITY;
        double phase = 0;
        for (int i = 0; i < V.length; i++) if (V[i][1] < maximum) {
                maximum = V[i][1];
                phase = V[i][0];
            }
        double I = getBand(BandName.I).get(0).getV(order, phase);
        return maximum - I;
    }

    public double VIMin(int order) {
        // fix me!
        double[][] V = getBand(BandName.V).get(0).getData(order, 100);
        double minimum = Double.NEGATIVE_INFINITY;
        double phase = 0;
        for (int i = 0; i < V.length; i++) if (V[i][1] > minimum) {
                minimum = V[i][1];
                phase = V[i][0];
            }
        double I = getBand(BandName.I).get(0).getV(order, phase);
        return minimum - I;
    }

    public double getPeriod() {
        return period;
    }

    public Band getBand(BandName bandName) {
        for (Band band : getBands()) if (band.getName() == bandName) return band;
        return null;
    }

    public Observation getDatfile(int name, Band band) {
        for (int i = 0; i < band.size(); i++) if (band.get(i).getName() == name) return band.get(i);
        return null;
    }

    public List<double[][]> getPlots(BandName band) {
        return getBand(band).getPlots();
    }

    public int getName() {
        return name;
    }

    public List<Band> getBands() {
        return Bands;
    }

    public void setPeriod(double period) {
        this.period = period;
    }

    public void setName(int name) {
        this.name = name;
    }

    public void setBands(List<Band> Bands) {
        this.Bands = Bands;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public PulsationMode getCl() {
        return cl;
    }

    public void setCl(PulsationMode cl) {
        this.cl = cl;
    }
}
